﻿<Window x:Class="BackgroundProcessing.CalculatorView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cal="http://www.caliburnproject.org"
        xmlns:fw="clr-namespace:BackgroundProcessing.Framework"
        xmlns:conv="clr-namespace:BackgroundProcessing.Converters"
        Title="Calculator"
        SizeToContent="Height"
        Width="561"
        Height="259">
	
	<!--
		Note: Sets the cursor for the window via databinding. 
		The source of the data is set to the singleton instance of IRunningActionsRegistry
		through the ResolveExtension.
		
		The converter takes care to convert the bool value of IRunningActionsRegistry.HasRunningActions
		to an appropriate cursor 
	-->
	<Window.Cursor>
		<Binding Source="{cal:Resolve fw:IRunningActionsRegistry}"
		         Path="HasRunningActions"
		         Converter="{x:Static conv:WaitCursorWhenTrueConverter.Instance}" />
	</Window.Cursor>

	<DockPanel>
		<StatusBar DockPanel.Dock="Bottom">
			<!-- The view associated with IRunningActionsRegistry instance is pushed inside StatusBarItem -->
			<StatusBarItem cal:View.Model="{cal:Resolve fw:IRunningActionsRegistry}" />
		</StatusBar>

		<StackPanel Margin="0 0 0 10">
			<Grid Margin="10">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>

				<TextBox x:Name="left"
				         Grid.Column="0" />
				<TextBlock Text="/"
				           Margin="10 0"
				           Grid.Column="1" />
				<TextBox x:Name="right"
				         Grid.Column="2" />
				<Border BorderBrush="Black"
				        BorderThickness="0 0 0 1"
				        Margin="10 0 0 0"
				        Grid.Column="3">
					<TextBlock x:Name="DivideResult" />
				</Border>
			</Grid>

			<!--Note: Calls the Divide action.  The framework must infer the trigger ande message type.-->
			<!--Note: UI availability will be updated.-->
			<!--Note: Action (indeterminated) progress is displayed in status bar.-->
			<Button Content="Execute division"
			        cal:Message.Attach="Divide(left.Text, right.Text) : DivideResult.Text" />

			<Grid Margin="10">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>

				<TextBlock Text="Factorial of"
				           Margin="10 0"
				           Grid.Column="0" />
				<TextBox x:Name="number"
				         Grid.Column="1" />
				<TextBlock Text="="
				           Margin="10 0"
				           Grid.Column="2" />
				<Border BorderBrush="Black"
				        BorderThickness="0 0 0 1"
				        Margin="10 0 0 0"
				        Grid.Column="3">
					<TextBlock x:Name="FactorialResult" />
				</Border>
			</Grid>

			<!--Note: Calls the Divide action.  The framework must infer the trigger ande message type.-->
			<!--Note: UI availability will be updated.-->
			<!--Note: Action progress is displayed in status bar.-->
			<Button Content="Calculate Factorial"
			        cal:Message.Attach="Factorial(number.Text) : FactorialResult.Text" />
			<Button Content="Another very long action"
			        cal:Message.Attach="VeryLongAction" />
		</StackPanel>
	</DockPanel>
</Window>